<template>
    <div class="container">
        <el-breadcrumb separator="->" class="bread">
            <el-breadcrumb-item><router-link to="/">首页</router-link></el-breadcrumb-item>
            <el-breadcrumb-item><router-link to="/orderlist">订单管理</router-link></el-breadcrumb-item>
            <el-breadcrumb-item>订单编辑</el-breadcrumb-item>
        </el-breadcrumb>
        <el-form label-width="100px" style="width:20%">
            <el-form-item :label="item" v-for="(item,index) in tableNames" :key="item.id">
                <el-input v-model="order[sqlNames[index]]" v-if="index == 12 || index == 0" :disabled="true"></el-input>
                <el-input v-model="order[sqlNames[index]]" v-else></el-input>
            </el-form-item>
            <el-button type="primary" @click="changeOrder">修改</el-button>
        </el-form>
    </div>
</template>
<script>
export default {
    data(){
        return {
            order:this.$route.params.item,
            tableNames:[
                '下单时间',
                '交易号',
                '物品SKU',
                '数量',
                '平米数',
                '销售单价',
                '订单运费',
                '交易手续费',
                '总计',
                '币种',
                '国家',
                'Coutrycode',
                '订单号',
                '快递方式',
                '付款方式',
                '销售渠道',
                '账号',
                '销售站点',
                '物品名称'
            ],
            sqlNames:[
                'strtime',
                'tradeid',
                'sku',
                'pcs',
                'square',
                'price',
                'extra',
                'charge',
                'total',
                'currency',
                'country',
                'countrycode',
                'orderid',
                'express',
                'paymethod',
                'channel',
                'user',
                'site',
                'product'
            ],
        }
    },
    methods:{
        changeOrder(){
            let params = new URLSearchParams();

            for(let i in this.order){
                params.append(i, this.order[i]);
            }
            
            this.$http.post('http://'+this.IP+'/api/changeOrder.php',params)
                .then(res=>{
                    this.$message.success(res.data.msg)
                    if(res.data.code == 20000){
                        setTimeout(()=>{
                            this.$router.replace('/orderlist')
                        },3000)
                    }
                })
        }
    }
}
</script>
<style lang="less" scoped>
    .container{
        .bread{
            margin: 20px 0;
        }
        .el-row{
            margin-bottom: 10px;
            border: 1px solid #eee;
        }
    }
</style>
